from pydantic import BaseModel, EmailStr, Field, constr
from typing import Optional
from datetime import datetime
from enum import Enum


class RoleEnum(str, Enum):
    admin = 'admin'
    user = 'user'


class User(BaseModel):
    """用户类
    """
    username: constr(min_length=4, max_length=11)  # type: ignore
    # 密码长度至少为8个字符
    password:  constr(min_length=6)  # type: ignore 加密后字符串
    email: EmailStr
    role: RoleEnum  # 使用枚举类型限制role的值
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
